<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateShopOrderExpressLogTable extends Migrator
{
    /**
     * Migrate Up.
     */
    public function up()
    {
        $table = $this->table('shop_order_express_log', ['comment' => '物流信息', 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci']);
        $table->addColumn('user_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '用户'])
            ->addColumn('order_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '订单'])
            ->addColumn('order_express_id', 'integer', ['limit' =>  11, 'default' => 0, 'comment' => '快递包裹'])
            ->addColumn('content', 'string', ['limit' => 512, 'null' => true, 'default' => null, 'comment' => '内容'])
            ->addColumn('change_date', 'datetime', ['null' => true, 'default' => null, 'comment' => '变动时间'])
            ->addColumn(Column::enum('status', [
                'noinfo',
                'collect',
                'transport',
                'delivery',
                'signfor',
                'refuse',
                'difficulty',
                'invalid',
                'timeout',
                'fail',
                'back'
            ])->setDefault('noinfo')->setComment('订单状态:noinfo=暂无信息,collect=已揽件,transport=运输中,delivery=派送中,signfor=已签收,refuse=用户拒收,difficulty=问题件,invalid=无效件,timeout=超时单,fail=签收失败,back=退回'))
            ->addColumn('create_time', 'integer', ['limit'  =>  10, 'null' => true, 'default' => null, 'comment' => '创建时间'])
            ->addColumn('update_time', 'integer', ['limit'  => 10, 'null' => true, 'default' => null, 'comment' => '更新时间'])
            ->addIndex('order_id')
            ->addIndex('order_express_id')
            ->create();
    }

    /**
     * Migrate Down.
     */
    public function down()
    {
        $table = $this->table('shop_order_express_log');
        $table->drop();
    }
}
